As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label Bash script. Show all posts

I haven't used Google App Engine for a while and I just needed to deploy for one line change in my code. I was prompted about the update of SDK when I tried to push the code. It can be ignored, but I always update SDK when the newer version is around.

I wrote the following Bash script to do that for that one line change:


This script downloads the latest version, checks the SHA1 (which I never bothered when I did update manually), removes the existing version, then unzip at current directory. It doesn't check versions and only works for Python on Linux SDK.

It could be buggy since I ran it virtually once and it did what I expected after I finished the code. So, basically, I didn't test it. Use at your own risk.

Used to do those steps manually, it didn't really take much time, less a minute (for typing commands) I would guess, but it's a boring task whenever Google App Engine SDK gets new update and that's quite frequent. As of 1.7.3, since the beginning of 2012 (v1.6.2), it's the ninth release of the year. Roughly one release per month.

I wasted quite some time to do such task, not anymore. I didn't even need to search for download page (didn't have it bookmarked), only need to run that script from now on when am told new version is available.

I had some issue with Google when querying about current time in different zone. Despite that, it seems too lazy if you can do in your own terminal. date command can achieve that with environment variable TZ, but you need to use perfect match timezone string, which you can found at /usr/share/zoneinfo/posix.

I found an answer of having world clock using a simple Bash script, and I expanded it a little more, the Gist:


If run cliclock.sh testzones cet and testzones file contains:
US/Pacific
Europe/Berlin
Chile/Continental
new york
Los Angeles
A snapshot of output looks like:
US/Pacific           2012-06-14 17:10:57 PDT
Europe/Berlin        2012-06-15 02:10:57 CEST
Chile/Continental    2012-06-14 20:10:57 CLT
America/New_York     2012-06-14 20:10:57 EDT
America/Los_Angeles  2012-06-14 17:10:57 PDT
CET                  2012-06-15 02:10:57 CEST
There are more to improve this script, such as options to add or to remove a zone. You can press Q to quit this script elegantly, so a few more lines should be enough to accept some additional zone since there is already a function for checking validity of input zone name. It can't recognize country codes, but it'd not be a huge task to add a group of zones associated to a country code.

Once in a while, I would loop a song and keep listening to it over and over again. That's what I am doing and curious what songs I had done with before. I wrote a quick Bash script to use Last.fm user.getRecentTracks API for listening timeline, here is the script:


You will need to obtain a Last.fm API key in order to use this script, the script is run with this syntax:
./obs.sh APIKEY USERNAME
It will retrieve last 1,000 tracks (using 5 API calls) that you have listened to and check consecutive plays of same tracks. Only three or more consecutive plays will be printed out as final results. The following screenshot is a sample output:


Each numbers means how many times the track had been played consecutively including starting play. I use URL to group the result, which serves a unique key and it's okay to be used in final results. Not really hard to read the artist's and track's names from it, although simple process can be used to perfect the output format, but it's not necessary. The first two of same URL are not a glitch of this script, there were some tracks played between them.

The script only retrieve 1,000 tracks, because for every 200 tracks, it's about 140K of XML file. Quite a waste of bandwidth for just the URLs of tracks. Of course, I can pipe through YQL to select <url> elements, but that is a bit overkill for this quick script. Although the API page listed JSON as alternative format, but that only returns empty response. This is not my first time to see JSON format returns empty response, I guess their API documentation is pretty out-of-date or just inaccurate to current status.

Here is a text version of the sample output, in case you wonder what these songs are:
 12 http://www.last.fm/music/Laura+Story/_/Blessings
 26 http://www.last.fm/music/Laura+Story/_/Blessings
  4 http://www.last.fm/music/Gipsy+Kings/_/Volare
 23 http://www.last.fm/music/Ellie+Goulding/_/Your+Song
 17 http://www.last.fm/music/John+Denver/_/Country+Roads+(West+Virginia)
 22 http://www.last.fm/music/Mikeschair/_/Someone+Worth+Dying+For
132 http://www.last.fm/music/Miracle+Of+Sound/_/Commander+Shepard

mr.sh is a simple script to record your current mood in range from 1 to 5. 1 is probably like 5617 (sxxt), 5 is like winning an one-million-dollar lottery.

It isn't ready to be released because I just wrote it yesterday and nothing is finished beside writing records to file. (And I finally have the chance to use my Bash script template)

The cause of this early and rush release is I just received an email about the contribution to a open source project last year, which I thought it was like help request or something like that when I first read the email subject.

Almost two hours later, I read it. It was from a recruiter of a famous company. (At least it is famous to me) Anyway, I immediately run

mr.sh 5 got an email from [company name] recruiter for potential job interview

Although I don't think I am the right person and I honestly replied with facts of mine (I didn't reject), but this really boosts up my mood.

I am not sure what kind of presentation or statistics this script should provide in the future. Some kind of mood chart? or five emoticons to represent five values?